<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Inv_sub extends CI_Controller {

	public function __construct(){
		parent::__construct();
		$this->load->model('wus');
		$this->load->model($this->session->userdata('formodel'));
		$this->load->library('variable');
	}

	public function index(){

	  $this->load->view('layouts/header',$this->variable->load_data($this->session->userdata('title')));
	  $this->load->view($this->session->userdata('formain'));
	  $this->load->view('layouts/footer');
	}
	public function add_form(){
				$this->load->view($this->session->userdata('foradd'),array(
					));
	}
	public function edit_form($id){

			$this->load->view($this->session->userdata('foredit'),array(
				'sub_data'	=> $this->inv_sub_model->get_subInv_data($id)
				));
		
	}
	public function view_form($id){
			$this->load->view($this->session->userdata('forview'),array(
				'sub_data'	=> $this->inv_sub_model->get_subInv_data($id)
				));
	}


	public function insert_sub_inv(){
		$data = array(
	 		':p_sub_code'		=> $this->input->post('invSub_code'),
	 		':p_sub_name'		=> $this->input->post('invSub_name'),
	 		':p_sub_desc'		=> $this->input->post('invSub_desc'),
	 		':p_user_id'		=> $this->session->userdata('user_id')
	 		);
	 	$this->inv_sub_model->insert_sub_inv($data);
	}

	public function update_sub_inv(){
		$data = array(
			':p_sub_id'			=> $this->input->post('hidden_sub_id_e'),
	 		':p_sub_code'		=> $this->input->post('edit_sub_code'),
	 		':p_sub_name'		=> $this->input->post('edit_sub_name'),
	 		':p_sub_desc'		=> $this->input->post('edit_sub_desc'),
	 		':p_user_id'		=> $this->session->userdata('user_id')
	 		);
	 	$this->inv_sub_model->update_sub_inv($data);
	}

	public function insert_sub_inv_locator(){
		$data = array(
			':p_inv_sub_id'		=> $this->input->post('hidden_sub_id'),
			':p_locator_code'	=> $this->input->post('locate_code'),
			':p_description'	=> $this->input->post('locate_desc'),
			':p_user_id'		=> $this->session->userdata('user_id')
			);


		$query= $this->inv_sub_model->insert_sub_inv_locator($data);
	 	if($query[0]->error == 1){
			echo json_encode($query);
		}else{
			$this->view_sub_locators($this->input->post('hidden_sub_id'));
		}
	}

	public function update_sub_inv_locator(){
		$data = array(
			':p_locator_id'		=> $this->input->post('h_loc_id'),
			':p_locator_code'	=> $this->input->post('locator_code_edit'),
			':p_description'	=> $this->input->post('locator_desc_edit'),
			':p_user_id'		=> $this->session->userdata('user_id')
			);


		$query= $this->inv_sub_model->update_sub_inv_locator($data);
		echo json_encode($query);

	}

	public function insert_sub_inv_locator_e(){
		$data = array(
			':p_inv_sub_id'		=> $this->input->post('hidden_sub_edit'),
			':p_locator_code'	=> $this->input->post('locate_code_e'),
			':p_description'	=> $this->input->post('locate_desc_e'),
			':p_user_id'		=> $this->session->userdata('user_id')
			);


		$query= $this->inv_sub_model->insert_sub_inv_locator($data);
	 	if($query[0]->error == 1){
			echo json_encode($query);
		}else{
			$this->view_sub_locators($this->input->post('hidden_sub_edit'));
		}
	}

	public function view_sub_locators($id){
		$query = $this->inv_sub_model->get_locators($id);
		echo json_encode($query);
	}

	public function search_subInv(){
			$code		= $this->input->post('subCode');
	 		$name		= $this->input->post('subName');

	 		$query = $this->inv_sub_model->search_subInv($code,$name);
			if(!empty($query)) {
			echo json_encode($query);
			}else{
				echo json_encode("none");
			}
		}

	public function get_locators_byID(){
		$result = $this->inv_sub_model->get_locators($this->input->post('sub_ids'));
		echo json_encode($result);
	}	
	
	 
}

/* End of file welcome.php */
/* Location: ./application/controllers/welcome.php */